package myaction.admin.courseinfo;

import myutil.DbUtil;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;

public class AdminCoursesDeleteAction extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doPost(request, response);
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String id = request.getParameter("c_id");
        try {
            Connection conn = DbUtil.getConn();
            String sql = "delete from t_courses where c_id=?;";
            PreparedStatement pstmt = conn.prepareStatement(sql);
            pstmt.setString(1, id);
            pstmt.executeUpdate();
            pstmt.close();
            conn.close();
            System.out.println("编号为" + id + "的课程已被删除！");
        } catch (Exception e) {
            e.printStackTrace();
        }
        response.sendRedirect("AdminCoursesFindAll");
    }

}
